package com.dxy.hms.service.impl;

import cn.hutool.core.util.StrUtil;
import com.dxy.hms.model.entity.RoomType;
import com.dxy.hms.mapper.RoomTypeMapper;
import com.dxy.hms.service.RoomTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

/**
* <p>
* 房型表 服务实现类
* </p>
*
* @author dxy
* @since 2024-10-29
*/
@Slf4j
@Service
public class RoomTypeServiceImpl extends ServiceImpl<RoomTypeMapper, RoomType> implements RoomTypeService {

    @Override
    public void add(RoomType entity) {
        baseMapper.insert(entity);
    }

    @Override
    public void updById(RoomType entity) {
        baseMapper.updateById(entity);
    }

    @Override
    public void delByIds(List<Long> ids) {
        baseMapper.deleteBatchIds(ids);
    }

    @Override
    public RoomType getDetail(Long id) {
        return baseMapper.selectById(id);
    }

    @Override
    public IPage<RoomType> getPage(Long pageNum, Long pageSize) {
        if (pageNum == null || pageNum <= 0) { pageNum = 1L; }
        if (pageSize == null || pageSize <= 0) { pageSize = 10L; }
        IPage<RoomType> page = new Page<>(pageNum, pageSize);
        Wrapper<RoomType> wrapper = new LambdaQueryWrapper<RoomType>();
        return baseMapper.selectPage(page, wrapper);
    }

    @Override
    public List<RoomType> getList(String name) {
        LambdaQueryWrapper<RoomType> wrapper = new LambdaQueryWrapper<RoomType>()
                .like(StrUtil.isNotEmpty(name), RoomType::getName, name)
                .last("limit 20");
        return baseMapper.selectList(wrapper);
    }

}
